//
//  BBSUser.m
//  BlackBambooCM-OC
//
//  Created by DKang on 2018/12/14.
//  Copyright © 2018年 ucanmax. All rights reserved.
//

#import "BBSUser.h"

static BBSUser *bbsUser;

@implementation BBSUser
+ (instancetype) sharedInstance {
    @synchronized(self) {
        if (!bbsUser) {
            [self new];
        }
    }
    return bbsUser;
}

+ (instancetype)allocWithZone:(struct _NSZone *)zone {
    @synchronized(self ) {
        if (!bbsUser) {
            bbsUser = [super allocWithZone:zone];
            return bbsUser;
        }
    }
    return nil;
}
- (id)init {
    @synchronized(self) {
        if (self = [super init]) {
            self.userToken = @"";
        }
        return self;
    }
}
- (void)saveToLocal {
    NSUserDefaults *uds = [NSUserDefaults standardUserDefaults];
    [uds setValue:[BBSUser sharedInstance].userToken forKey:BBSTOKEN];
    [uds synchronize];
}

- (void)getUserInfo {
    NSUserDefaults *uds = [NSUserDefaults standardUserDefaults];
    [BBSUser sharedInstance].userToken =  [uds objectForKey:BBSTOKEN];
}
- (BOOL)hasLogin{
    if([[BBSUser sharedInstance].userToken isEqualToString:@""]){
        return NO;
    }else {
        return YES;
    }
}
- (void)loginWith:(NSString *)name password:(NSString *)password captcha:(NSString *)captcha success:(void (^)(id responseObject))success failure:(void (^)(NSString *error))failure  {
    [[WYNetwork sharedWYNetwork] postLogin:name password:password captcha:captcha success:^(id responseObject) {
        NSLog(@"%@",responseObject);
    } failure:^(NSString *error) {
        NSLog(@"%@",error);
    }];
}
@end
